<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 长度为三的不同回文子序列 -->
    <script>
      var countPalindromicSubsequence = function (s) {
        let res = 0
        for (let i = 0; i < 26; i++) {
          let item = String.fromCharCode(97 + i)
          let left = s.indexOf(item)
          let right = s.lastIndexOf(item)
          if (right - left < 2) {
            //如果字符item不存在于字符串s中或left和right之间不存在字符。
            continue
          }
          let sequence = new Set()
          for (let j = left + 1; j < right; j++) {
            sequence.add(s[j])
          }
          res = res + sequence.size
        }
        return res
      }
      console.log(countPalindromicSubsequence('aabca'))
    </script>
  </body>
</html>
